<template>
  <div v-if="examData.id">

    <div v-if="examData.questions">
      <exam-info-view-m :timeCount="timeCount" @sendTipCardClick="tipCardClick" @sendSubmitClick="submitClick"></exam-info-view-m>
      <exam-question-m v-model="selectedIndex" :question-list="examData.questions" :answer-data="answerData"
                       :exam-type="5" @sendAnswerClick="answerClick" @sendSubmitClick="submitClick"></exam-question-m>


      <van-popup v-model="showTipCover" position="bottom">
        <tip-card-m v-model="selectedIndex" :question-list="examData.questions" :answer-data="answerData" @sendCloseTipCard="closeTipCard"></tip-card-m>
      </van-popup>
    </div>
    <div v-else class="emptyPage">
      <img src="/web-hft-ee/static/img/pc/null_message.png">
      <p>没有错题</p>
    </div>


  </div>
</template>

<script>

  import TipCardM from '../components/TipCardM'
  import ExamQuestionM from '../components/ExamQuestionM'
  import ExamInfoViewM from '../components/ExamInfoViewM'
  import {Popup, Toast} from 'vant'
  import ExamTool from '../ExamTool'

  Vue.use(Popup)

  export default {
    name: 'overall-m',
    //examType 1:统筹考试 2:普通考试 3:模拟考试 4:题库练习
    data () {
      return {
        examId: this.$route.params.examId,
        subjectId: this.$route.params.subjectId || 0,
        showTipCover: false,
        timeCount: 0,
        selectedIndex: 0,
        answerData: {},
        examData: {},
      }
    },
    components: {
      TipCardM,
      ExamQuestionM,
      ExamInfoViewM
    },
    computed: {},
    mounted () {
      this.loadExamError()
    },
    methods: {

      loadExamError () {
        ExamTool.getErrorExamDetail(this.examId, this.subjectId, (data) => {
          this.examData = data
          this.timeCount = 0
        })
      },
      answerClick() {
        let answerData = {...this.answerData}
        this.answerData = answerData
      },
      //打开答题卡
      tipCardClick() {
        this.showTipCover = true
      },
      //关闭答题卡
      closeTipCard() {
        this.showTipCover = false
      },
      //答案提交
      submitClick () {

        Toast.loading({
          duration: 0,
          message: '正在交卷',
          forbidClick: true,
        });

        ExamTool.submitExam(this.examId, this.subjectId, this.answerData).then((result) => {

          Toast.clear()
          let data = result.responseData
          this.$_router.replace(`/exam/result/practice/${this.subjectId}/${this.examId}/${data.id}/1`)

        }).catch((err) => {

          Toast.clear()
        })
      }
    }
  }
</script>

<style scoped>

</style>
